<?php

namespace apps\admin\controllers;

use apps\common\components\Common;
use apps\common\controllers\AdminController;
use apps\common\facades\PDO;
use apps\common\models\MasterModel;
use mix\facades\Request;
use mix\facades\Session;

/**
 * 默认控制器
 * @author 刘健 <coder.liu@qq.com>
 */
class IndexController extends AdminController
{

    // 默认动作
    public function actionIndex()
    {
        if (Request::isPost()) {
            $request = Request::post();
            $res = MasterModel::init("admin_user")->getOne(array('WHERE 1=1 AND status = 1 AND username =' . "'{$request['username']}'"));
            if (!$res) return $this->error('账号或密码错误');
            if (Common::password($request['password'], $res['salt']) != $res['password']) {
                return $this->error('账号或密码错误');
            }
            Session::set('user', $res);
           return Common::jump('main/index');
//            return $this->success('登陆成功', Common::url('main/index'));
        } else {
            if (Session::get('user')) {
                return Common::jump('main/index');
            }
            return $this->render('index');
        }
    }


    public function actionTest()
    {
        app()->dump(json_encode($_SERVER), true);
    }

}
